//
//  AppDelegate.m
//  EasyToo
//
//  Created by 郑 哲 on 6/9/13.
//
//

#import "AppDelegate.h"
#import "MapViewController.h"
#import "MainViewController.h"
#import "GuideViewController.h"
#import "LeveyTabBarController.h"
#import "LoginViewController.h"
#import "UPViewController.h"
#import "ShoppingViewController.h"
#import "SearchViewController.h"
#import "DeviceUtil.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = BackgroundColor;
    [self.window makeKeyAndVisible];
    
    //初始化百度地图
    _mapManager = [[BMKMapManager alloc] init];
    BOOL ret = [_mapManager start:@"980b1e87240be68942bca167f961171e" generalDelegate:nil];
    if (!ret)
    {
        NSLog(@"manager start failed");
    }
    
//    [self initHomePageView];
//    [self initEntryView];
//    [self initMainView];

    [self initTabView];
//    [self initUPView];
    //首次启动加载用户引导页
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"Launched"])
    {
        [GuideViewController show];
    }
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)initHomePageView
{
    HomePageViewController* myHomePageView = [[HomePageViewController alloc] init];
    
    self.navigationCtrl = [[UINavigationController alloc] initWithRootViewController:myHomePageView];
    
    self.window.rootViewController = self.navigationCtrl;
    [myHomePageView release];
    
    [self.navigationCtrl.navigationBar setTintColor:[UIColor redColor]];
}

- (void)initMainView
{
    MainViewController *mainView = [[MainViewController alloc] init];
    
    self.navigationCtrl = [[UINavigationController alloc] initWithRootViewController:mainView];
    self.window.rootViewController = self.navigationCtrl;
    
    [mainView release];
    
    [self.navigationCtrl.navigationBar setTintColor:[UIColor redColor]];
}

- (void)initTabView
{
    MainViewController *view0 = [[[MainViewController alloc] init] autorelease];
    SearchViewController *view1 = [[[SearchViewController alloc] init] autorelease];
    ShoppingViewController *view2 = [[[ShoppingViewController alloc] init] autorelease];
    MapViewController *view3 = [[[MapViewController alloc] init] autorelease];
    LoginViewController *view4 = [[[LoginViewController alloc] init] autorelease];
    
    UINavigationController *nav0 = [[[UINavigationController alloc] initWithRootViewController:view0] autorelease];
    [nav0.navigationBar setTintColor:[UIColor redColor]];
    
    UINavigationController *nav1 = [[[UINavigationController alloc] initWithRootViewController:view1] autorelease];
    [nav1.navigationBar setTintColor:[UIColor redColor]];
    
    UINavigationController *nav2 = [[[UINavigationController alloc] initWithRootViewController:view2] autorelease];
    [nav2.navigationBar setTintColor:[UIColor redColor]];
    
    UINavigationController *nav3 = [[[UINavigationController alloc] initWithRootViewController:view3] autorelease];
    [nav3.navigationBar setTintColor:[UIColor redColor]];
    
    UINavigationController *nav4 = [[[UINavigationController alloc] initWithRootViewController:view4] autorelease];
    [nav4.navigationBar setTintColor:[UIColor redColor]];
    
    
    NSArray *viewCtrlArray = [[[NSArray alloc] initWithObjects:nav0, nav1, nav2, nav3, nav4, nil] autorelease];
    
	NSMutableDictionary *imgDic = [NSMutableDictionary dictionaryWithCapacity:3];
	[imgDic setObject:[UIImage imageNamed:@"mainHome"] forKey:@"Default"];
	[imgDic setObject:[UIImage imageNamed:@"mainHomeSelected"] forKey:@"Highlighted"];
	[imgDic setObject:[UIImage imageNamed:@"mainHomeSelected"] forKey:@"Seleted"];
	NSMutableDictionary *imgDic2 = [NSMutableDictionary dictionaryWithCapacity:3];
	[imgDic2 setObject:[UIImage imageNamed:@"mainSearch"] forKey:@"Default"];
	[imgDic2 setObject:[UIImage imageNamed:@"mainSearchSelected"] forKey:@"Highlighted"];
	[imgDic2 setObject:[UIImage imageNamed:@"mainSearchSelected"] forKey:@"Seleted"];
	NSMutableDictionary *imgDic3 = [NSMutableDictionary dictionaryWithCapacity:3];
	[imgDic3 setObject:[UIImage imageNamed:@"mainShop"] forKey:@"Default"];
	[imgDic3 setObject:[UIImage imageNamed:@"mainShopSelected"] forKey:@"Highlighted"];
	[imgDic3 setObject:[UIImage imageNamed:@"mainShopSelected"] forKey:@"Seleted"];
	NSMutableDictionary *imgDic4 = [NSMutableDictionary dictionaryWithCapacity:3];
	[imgDic4 setObject:[UIImage imageNamed:@"mainLocal"] forKey:@"Default"];
	[imgDic4 setObject:[UIImage imageNamed:@"mainLocalSelected"] forKey:@"Highlighted"];
	[imgDic4 setObject:[UIImage imageNamed:@"mainLocalSelected"] forKey:@"Seleted"];
	NSMutableDictionary *imgDic5 = [NSMutableDictionary dictionaryWithCapacity:3];
	[imgDic5 setObject:[UIImage imageNamed:@"mainUser"] forKey:@"Default"];
	[imgDic5 setObject:[UIImage imageNamed:@"mainUserSelected"] forKey:@"Highlighted"];
	[imgDic5 setObject:[UIImage imageNamed:@"mainUserSelected"] forKey:@"Seleted"];
	
	NSArray *imgArr = [NSArray arrayWithObjects:imgDic,imgDic2, imgDic3, imgDic4, imgDic5, nil];
    
    //创建UITabBarController控制器
	LeveyTabBarController *leveyTabBarController = [[LeveyTabBarController alloc] initWithViewControllers:viewCtrlArray imageArray:imgArr];
    
    [leveyTabBarController.navigationItem setTitle:@"一指通科技"];

    [leveyTabBarController setTabBarTransparent:NO];
//    self.navigationCtrl = [[UINavigationController alloc] initWithRootViewController:leveyTabBarController];
    self.window.rootViewController = leveyTabBarController;
//    [self.navigationCtrl.navigationBar setTintColor:[UIColor redColor]];
   
}

- (void)initUPView
{
    UPViewController* root = [[UPViewController alloc] init];
    UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:root];
    [root release];
    
    self.window.rootViewController = nav;;
    
}


@end
